package cn.elricyu.tt.ui.item.comp;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;

public class ActionButton extends Button {
	private ActionButton parent = null;
	private List<Composite> compositeList = new ArrayList<Composite>();
	private List<Control> controlList = new ArrayList<Control>();

	public ActionButton(Composite parent, int style) {
		super(parent, style);
	}

	public void loadStatus() {
		boolean isChecked = this.getSelection();
		if (parent != null) {
			isChecked = isChecked & parent.getSelection();
		}
		for (Composite composite : compositeList) {
			composite.setEnabled(isChecked);
		}
		for (Control control : controlList) {
			control.setEnabled(isChecked);
		}
	}

	public void addComposite(Composite composite) {
		compositeList.add(composite);
	}

	@Override
	protected void checkSubclass() {
	}

	public void addControl(Control control) {
		if (control instanceof ActionButton) {
			ActionButton subButton = (ActionButton) control;
			subButton.parent = this;
		}
		controlList.add(control);
	}
}
